package com.itheima.pinda.controller.transportline;


import com.itheima.pinda.DTO.entity.pojo.transportline.PdTransportLineType;
import com.itheima.pinda.DTO.entity.vo.Results;
import com.itheima.pinda.DTO.entity.vo.StatusCode;
import com.itheima.pinda.feign.service.transportline.PdTransportLineTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 线路类型表 前端控制器
 * </p>
 *
 * @author xy
 * @since 2021-11-15
 */
@RestController
@RequestMapping("/base/transportlinetype")
public class PdTransportLineTypeController {

    @Autowired
    private PdTransportLineTypeService transportLineTypeService;

    /**
     * 线路类型查询
     * @param typeNumber
     * @param name
     * @param agencyType
     * @return
     */
    @PostMapping("/")
    public Results<List<PdTransportLineType>> findAdvance(@RequestBody String typeNumber ,
                                                          @RequestBody String name ,
                                                          @RequestBody String agencyType){

        List<PdTransportLineType> advance = transportLineTypeService.findAdvance(typeNumber, name, agencyType);

        return new Results<>(true,StatusCode.OK,"查询成功",advance);

    }

    @PostMapping("/delete")
    public Results disable(@RequestBody String id){
        Integer disable = transportLineTypeService.disable(id);
        if (disable>0){
            return new Results(true,StatusCode.OK,"禁用成功",null);
        }
        return new Results<>(false,StatusCode.ERROR,"禁用失败",null);

    }

    @PostMapping("/insert")
    public Results insert(@RequestBody PdTransportLineType transportLineType){
        Integer disable = transportLineTypeService.insert(transportLineType);
        if (disable>0){
            return new Results(true,StatusCode.OK,"添加成功",null);
        }
        return new Results<>(false,StatusCode.ERROR,"添加失败",null);

    }

    @PostMapping("/update")
    public Results update(@RequestBody PdTransportLineType transportLineType){
        Integer disable = transportLineTypeService.update(transportLineType);
        if (disable>0){
            return new Results(true,StatusCode.OK,"修改成功",null);
        }
        return new Results<>(false,StatusCode.ERROR,"修改失败",null);

    }


}
